﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Chinaer.Model.Common;
using Chinaer.Core.Helper;

namespace Chinaer.Bll
{
    public class AdministratorCaoZuo : Repository, IBll.IAdministratorCaoZuo
    {
        private static AdministratorCaoZuo _administratorCaoZuo = null;
        public static AdministratorCaoZuo Instance
        {
            get
            {
                if (_administratorCaoZuo == null)
                {
                    _administratorCaoZuo = new AdministratorCaoZuo();
                }
                return _administratorCaoZuo;
            }
            set
            {
                _administratorCaoZuo = value;
            }
        }
        private IDao.IAdministrator_CaoZuoDAO administratorCaoZuoDAO = new Chinaer.Dao.AdministratorCaoZuoDAO();
        public JsonResult Add(DTO.Administrator_CaoZuoDTO t)
        {
            if (t.CheckIsNull().Success == false)
            {
                return t.CheckIsNull();
            }
            JsonResult jsonResult = new JsonResult();
            Model.Entities.Model_Administrator_CaoZuo model_AdministratorCaoZuo = new Model.Entities.Model_Administrator_CaoZuo();
            Chinaer.Core.Helper.DTOtoEntityObjectHelper.Instance.DTOtoEntityObject(t, model_AdministratorCaoZuo);
            if (string.IsNullOrEmpty(model_AdministratorCaoZuo.ID) || model_AdministratorCaoZuo.ID.Trim() == "")
            {
                model_AdministratorCaoZuo.ID = Chinaer.Core.Helper.GenerateIDHelper.GenerateID();
            }
            jsonResult.Success = administratorCaoZuoDAO.Add(model_AdministratorCaoZuo);
            return jsonResult;
        }

        public JsonResult Delete(DTO.Administrator_CaoZuoDTO t)
        {
            if (t.CheckIsNull().Success == false)
            {
                return t.CheckIsNull();
            }
            JsonResult jsonResult = new JsonResult();
            Model.Entities.Model_Administrator_CaoZuo model_AdministratorCaoZuo = new Model.Entities.Model_Administrator_CaoZuo();
            Chinaer.Core.Helper.DTOtoEntityObjectHelper.Instance.DTOtoEntityObject(t, model_AdministratorCaoZuo);
            jsonResult.Success = administratorCaoZuoDAO.Delete(model_AdministratorCaoZuo);
            return jsonResult;
        }

        public JsonResult Delete(string id)
        {
            JsonResult jsonResult = new JsonResult();
            jsonResult.Success = administratorCaoZuoDAO.Delete(id);
            return jsonResult;
        }

        public JsonResult Update(DTO.Administrator_CaoZuoDTO t)
        {
            if (t.CheckIsNull().Success == false)
            {
                return t.CheckIsNull();
            }
            JsonResult jsonResult = new JsonResult();
            Model.Entities.Model_Administrator_CaoZuo model_AdministratorCaoZuo = new Model.Entities.Model_Administrator_CaoZuo();
            Chinaer.Core.Helper.DTOtoEntityObjectHelper.Instance.DTOtoEntityObject(t, model_AdministratorCaoZuo);
            jsonResult.Success = administratorCaoZuoDAO.Update(model_AdministratorCaoZuo);
            return jsonResult;
        }

        public DTO.Administrator_CaoZuoDTO GetByID(string id)
        {
            Model.Entities.Model_Administrator_CaoZuo model_administratorCaoZuo = new Model.Entities.Model_Administrator_CaoZuo();
            model_administratorCaoZuo = administratorCaoZuoDAO.GetByID(id);
            DTO.Administrator_CaoZuoDTO administratorCaoZuoDTO = new DTO.Administrator_CaoZuoDTO();
            Chinaer.Core.Helper.DTOtoEntityObjectHelper.Instance.DTOtoEntityObject(model_administratorCaoZuo, administratorCaoZuoDTO);
            return administratorCaoZuoDTO;
        }
    }
}
